Ext.namespace('Attivita.form');

	
Attivita.form.formTab = function(config){

	var _this = this;

	var itemDefaults = { anchor:'99%'}

	var record;

	var idattivita = {xtype:'hidden', name:'idattivita', id:'idAttivita'}
	var idanagrich = {xtype:'hidden', name:'idanagrich'}
	var idente = {xtype:'hidden', name:'id_ente', value: appContext.currentEnte}
	var idprocedure = {xtype:'hidden', name:'idprocedure', value: appContext.currentProcedure}
	//var idlegrapp = {xtype:'hidden', name:'id_legrapp'}


// ############## TAB 0 #####################
	var ragionesociale = {
			xtype:'trigger', 
			onTriggerClick : function(){
				var main = new Anagrafica.app.Main({
					sesso:'G',
					disableBtnNuovaIscrizione:true,
					onCaricaSelezione: function(record){
						var dati = {
							data:{
								idanagrich:record.data.idAdresse,
								ragsociale:record.data.ragsoc,
								via:record.data.indir,
 								nciv:record.data.nciv,
								codfisc:record.data.codfisc,
								cap:record.data.cap,
								partiva:record.data.partiva,
								citta:record.data.localita,
								prov:record.data.prov
							}
						}
						
						_this.getForm().loadRecord(dati);
// 						console.dir(record.data);
					}
				});
				
			}, 
			readOnly : true,
			fieldLabel:'Ragione sociale' ,
			fit:true,
			triggerClass : 'x-trigger-search' ,
			itemCls  : 'x-trigger-comp-element' ,
			name:'ragsociale',
			id:'trigger-ragsoc' ,
			allowBlank:false,
			width:450

        }
	

	
	var via = {xtype:'textfield',  name:'via', fieldLabel:'Via', allowBlank:false, readOnly:true, width:340}
	  
	var civico = {xtype:'textfield', name:'nciv', fieldLabel:'Numero civico', allowBlank:false, readOnly:true, width:50}

//	var cap = {xtype:'textfield',  name:'cap', fieldLabel:'CAP', allowBlank:false, readOnly:true, width:60, maxLength:5, minLength:5, maxLengthText:'La lunghezza è di 5 caratteri', minLengthText:'La lunghezza è di 5 caratteri'}
	var cap = {xtype:'textfield',  name:'cap', fieldLabel:'CAP', allowBlank:false, readOnly:true, width:60}

	var citta = {xtype:'textfield', name:'citta', fieldLabel:'Città', labelWidth: 50, allowBlank:false, readOnly:true, width:280}

//	var provincia = {xtype:'textfield', name:'prov', fieldLabel:'Provincia', allowBlank:false, readOnly:true, width:55, maxLength:2, minLength:2, maxLengthText:'La lunghezza è di 2 caratteri', minLengthText:'La lunghezza è di 2 caratteri'}
	var provincia = {xtype:'textfield', name:'prov', fieldLabel:'Provincia', allowBlank:false, readOnly:true, width:55}
	
	var codfisc = {xtype:'textfield', colspan:2, name:'codfisc', fieldLabel:'Codice Fiscale', allowBlank:true, readOnly:true, width:180}
	
	var partiva = {xtype:'textfield', colspan:2,  name:'partiva', fieldLabel:'Partita IVA', allowBlank:true, readOnly:true, width:180}
	
	
	
	
	var colRagSoc = {
		layout:'form',
		columnWith:1,
		border:false,
		autoheight:true,
		//style:'padding:10px 5px 5px 10px',
		items:[idente, idattivita, idanagrich, ragionesociale],
		defaults: itemDefaults
	} 
	
	var panRagSoc = {
		layout:'column',
		autoheight:true,
		items:[colRagSoc],
		style:'padding:10px 5px 5px 10px',
		defaults: itemDefaults,
	
	}
	
	
	
	
	var colSxCodfisc = {
		layout:'form',
		columnWith:0.5,
		border:false,
		autoheight:true,
		//padding:'10px',
		items:[codfisc],
		defaults: itemDefaults
	} 
	var colDxPiva = {
		layout:'form',
		columnWith:0.5,
		labelWidth: 60,
		border:false,
		autoheight:true,
		//padding:'10px',
		style:'padding:0px 0px 0px 25px',
		items:[partiva],
		defaults: itemDefaults
	} 
	var panCodfiscPiva = {
		layout:'column',
		autoheight:true,
		style:'padding:5px 5px 5px 10px',
		//padding:'5px 10px 5px 10px',
		items:[colSxCodfisc, colDxPiva],
		defaults: itemDefaults
	}



	var colSxIndir = {
		layout:'form',
		columnWith:0.7,
		labelWidth:30,
		border:false,
		autoheight:true,
		//padding:'10px',
		items:[via],
		defaults: itemDefaults
	}
	var colDxIndir = {
		layout:'form',
		columnWith:0.3,
		border:false,
		autoheight:true,
		style:'padding: 0px 0px 0px 25px',
		items:[civico],
		defaults: itemDefaults
	}
	var panIndir = {
		layout:'column',
		autoheight:true,
		style:'padding:5px 5px 5px 10px',
		//padding:'5px 10px 5px 10px',
		items:[colSxIndir, colDxIndir],
		defaults: itemDefaults
	}


	var colSxCap = {
		labelWidth: 30,
		layout:'form',
		columnWith:0.3,
		border:false,
		autoheight:true,
		//style:'padding:10px',
		items:[cap],
		defaults: itemDefaults
	}
	var colCenterCitta = {
		labelWidth: 40,
		layout:'form',
		columnWith:0.5,
		border:false,
		autoheight:true,
		style:'padding:0px 0px 0px 10px',
		items:[citta],
		defaults: itemDefaults
	}
	var colDxProv = {
		labelWidth: 60,
		layout:'form',
		columnWith:0.2,
		border:false,
		autoheight:true,
		style:'padding:0px 0px 0px 10px',
		items:[provincia],
		defaults: itemDefaults
	}
	var panCapCitta = {
		layout:'column',
		style:'padding:5px 10px 5px 10px',
		autoheight:true,
		items:[colSxCap, colCenterCitta, colDxProv],
		defaults: itemDefaults
	}


//#################### old
/*	var formagiuridica = {
		xtype:'trigger', 
		onTriggerClick : function(){
		//apertura window
			var formeGiur = new Attivita.formegiur.WinFormeGiuridiche({
				onCaricaSelezione: function(nodo){
				
					var formagiuridica = {data:{ formagiuridica:nodo.attributes.text }}
					_this.getForm().loadRecord(formagiuridica);
				}
				
			})
			formeGiur.show();
		}, 
		readOnly : true,
		fieldLabel:'Forma Giuridica' ,
		fit:true,
		triggerClass : 'x-trigger-search' ,
		name:'formagiuridica',
		id:'trigger-formagiuridica' ,
		allowBlank:true,
		width:450,
		defaults: itemDefaults
	}
*/
//#################### fine old
//#################### new
	Ext.app.SearchField = Ext.extend(
			
			Ext.form.TwinTriggerField,
			{
				initComponent : function(){
					Ext.app.SearchField.superclass.initComponent.call(this);
					this.on('specialkey', function(f, e){
						if(e.getKey() == e.ENTER){
							this.onTrigger2Click();
						}
					},this);
				},
		    validationEvent:false,
		    validateOnBlur:false,
		    trigger1Class:'x-form-search-trigger',
		    trigger2Class:'x-form-clear-trigger',
		    hideTrigger1:false,
		    hideTrigger2:false,
		    onTrigger1Click : function(record){
					//apertura window
					var formeGiur = new Attivita.formegiur.WinFormeGiuridiche({
						onCaricaSelezione: function(nodo){
						
							var formagiuridica = {data:{ formagiuridica:nodo.attributes.text }}
							_this.getForm().loadRecord(formagiuridica);
						}
						
					})
					formeGiur.show();
		    },	
		
		    onTrigger2Click : function(){
		       	this.setRawValue('');
		    }
		
	});//Ext.app.SearchField
		
	var formagiuridica = new Ext.app.SearchField({
			
		readOnly : true,
		fieldLabel:'Forma Giuridica' ,
		fit:true,
		name:'formagiuridica',
		id:'trigger-formagiuridica' ,
		allowBlank:true,
		width:450,
		defaults: itemDefaults
			
	})	
//#################### fine new	
	var colFormaGiur = {
		layout:'form',
		columnWith:1,
		border:false,
		autoheight:true,
		style:'padding:5px 10px 5px 10px',
		items:[formagiuridica],
		defaults: itemDefaults
	} 
	var panFormaGiur = {
		layout:'column',
		autoheight:true,
		items:[colFormaGiur],
		defaults: itemDefaults,
	
	}


	var idLegRapp = {xtype:'hidden', name:'id_legrapp', id:'attivitaIdLegRapp', allowBlank:true}

	
	//########### nuovo
	Ext.app.SearchField = Ext.extend(
		
		Ext.form.TwinTriggerField,
		{
			initComponent : function(){
				Ext.app.SearchField.superclass.initComponent.call(this);
				this.on('specialkey', function(f, e){
					if(e.getKey() == e.ENTER){
						this.onTrigger2Click();
					}
				},this);
			},
	    validationEvent:false,
	    validateOnBlur:false,
	    trigger1Class:'x-form-search-trigger',
	    trigger2Class:'x-form-clear-trigger',
	    hideTrigger1:false,
	    hideTrigger2:false,
	    onTrigger1Click : function(record){
	    	var main = new Anagrafica.app.Main({
				onCaricaSelezione: function(record){
					var datilegrapp = {
							data:{
								id_legrapp:record.data.idAdresse,
								legrapp:record.data.ragsoc
								//Ext.getCmp('idlegrapp').setValue(record.data.idAdresse)
							}
						}							
						_this.getForm().loadRecord(datilegrapp)
				}
			});
	    },	
	
	    onTrigger2Click : function(){
	       	this.setRawValue('');
	    	Ext.getCmp('attivitaIdLegRapp').setRawValue('');
	    }
	
	});//Ext.app.SearchField
	
	
	
	var legrapp = new Ext.app.SearchField({
			
		readOnly : true,
		fieldLabel:'Legale rappresentante' ,
		fit:true,
		name:'legrapp',
		allowBlank:true,
		width:450
			
	})
	
	
	//######### fine nuovo
	

	var colLegRapp = {
		layout:'form',
		//columnWidth:1,
		border:false,
		autoHeight:true,
		style:'padding:5px 10px 0px 10px',
		items:[idLegRapp, legrapp],
		defaults: itemDefaults
	} 
	var panLegRapp = {
		layout:'column',
		autoHeight:true,
		items:[colLegRapp],
		defaults: itemDefaults,
	
	}

	var nrea = {xtype:'textfield', id:'nrea', name:'nrea', fieldLabel:'Numero iscrizione Registro Imprese', allowBlank:true, width:450}

	var colNRea = {
		layout:'form',
		//columnWidth:1,
		border:false,
		autoHeight:true,
		style:'padding:0px 10px 0px 10px',
		items:[nrea],
		defaults: itemDefaults
	} 
	var panNRea = {
		layout:'column',
		autoHeight:true,
		items:[colNRea],
		defaults: itemDefaults
	
	}


//	var descprod = {xtype:'textfield', name:'cicloprod', fieldLabel:'Descrizione Ciclo Produttivo', allowBlank:true, width:450}
//	var colCicloP = {
//		layout:'form',
//		columnWith:1,
//		border:false,
//		autoheight:true,
//		style:'padding:0px 10px 0px 10px',
//		items:[descprod],
//		defaults: itemDefaults
//	} 
//	var panCicloP = {
//		layout:'column',
//		autoheight:true,
//		items:[colCicloP],
//		defaults: itemDefaults
//	
//	}



// ------------------------------------------
	
// ############## TAB 1 #####################


	var naddetti = {xtype:'numberfield', ids:'naddetti', name:'naddetti', fieldLabel:'Numero addetti', allowBlank:true}
	var istat =  {xtype:'textfield', name:'istat_principale', fieldLabel:'Codice ISTAT principale', allowBlank:true}
	
	var panNaddetti = {
		layout:'form',
		style:'padding:10px 10px 5px 10px',
		autoHeight:true,
		xtype:'fieldset',
		items:[naddetti,istat],
		defaults: itemDefaults
	}
 
	var dsIstatSecond = new Ext.data.JsonStore({
		url:'',
		fields:['codice','descrizione']

	})
	
	var cmSorg = new Ext.grid.ColumnModel([
		{ header:'Codice ISTAT', dataIndex:'codice', width:100, editor: new Ext.form.TextField({ allowBlank:false})},
		{ header:'Descrizione', dataIndex:'descrizione', width:350, editor: new Ext.form.TextField({ allowBlank:false})}
	])
	
	var insertIstatSecond = Ext.data.Record.create([
		{name:'codice', type:'string'},
		{name:'descrizione', type:'string'}
	])
	var gridIstatSecond = new Ext.grid.EditorGridPanel({
		cm: cmSorg,
		ds: dsIstatSecond,
// 		name:'istat_secondari',
		width:600,
		height:180,
		style:'padding:10px',
		title:'Codici ISTAT Secondari',
		frame:true,
//		clicksToEdit:1,
		sm: new Ext.grid.RowSelectionModel({singleSelect: true}), 
		tbar:[{
			text:'inserisci',
			handler: function(){
				var nuovo = new insertIstatSecond({
					codice:'',
					descrizione:''

				});
				gridIstatSecond.stopEditing();
				dsIstatSecond.insert(0,nuovo);
				gridIstatSecond.startEditing(0,0);
			}
		},{
			text:'elimina',
			handler: function(){

				var selModel = gridIstatSecond.getSelectionModel();
				var selection = selModel.getSelected();

				deletedIstatTmp.push(selection.data);
				dsIstatSecond.remove(selection);
//				console.dir(deletedIstatTmp);			
			}
		
		}]

	})


	
	
	
	

// -----------------------------------------

	
// ############## TAB 2 #####################

	var cicloProd = {xtype:'htmleditor', height:120, width:400, enableFont: false, enableLinks: false, enableSourceEdit: false, name:'desc_cicloprod', fieldLabel:'Ciclo produzione - descrizione'}
	
	var note = {xtype:'htmleditor', height:120, width:400, enableFont: false, enableLinks: false, enableSourceEdit: false, name:'note', fieldLabel:'Note'} 

// ------------------------------------------

// ############## TAB 3 #####################

	var dsUnita = new Ext.data.JsonStore({
		url:'/commongest/CommonServlet/anagditte/attivitaSel',
		fields:['idattivita',
		        'ragsociale',
		        'attivitalocale',
		        'citta',
		        'cap',
		        'prov',
		        'via',
		        'nciv',
		        'istat_principale',
		        'naddetti',
		        'istat_secondari',
		        'desc_cicloprod',
		        'note'
		        ]

	})
	
	var cmUnita = new Ext.grid.ColumnModel([
   		{ header:'Descrizione', dataIndex:'ragsociale', width:150, editor: new Ext.form.TextField({ allowBlank:false})},	                                        
//		{ header:'Citta', dataIndex:'citta', width:150, editor: new Ext.form.TextField({ allowBlank:false})},
//		{ header:'Provincia', dataIndex:'prov', width:70, editor: new Ext.form.TextField({ allowBlank:false})},
		{ header:'CAP', dataIndex:'cap', width:50, editor: new Ext.form.TextField({ allowBlank:false})},
		{ header:'Via', dataIndex:'via', width:150, editor: new Ext.form.TextField({ allowBlank:false})},
		{ header:'Civico', dataIndex:'nciv', width:50, editor: new Ext.form.TextField({ allowBlank:false})},
//		{ header:'Istat', dataIndex:'istat_principale', width:150, editor: new Ext.form.TextField({ allowBlank:false})}

	]);
	
	var insertUnita = Ext.data.Record.create([
		{name:'citta', type:'string'},
		{name:'via', type:'string'},
		{name:'civico', type:'string'}

	]);
	
	var apriUl = function(){
	
	
	}
	
	var gridUnita = new Ext.grid.EditorGridPanel({
		cm: cmUnita,
		ds: dsUnita,		
		width:600,
		height:250,
		style:'padding:10px',
		title:'Unità Locali',
		id:'attivitaForm_UnitaLocali',
		frame:true,
//		clicksToEdit:1,
		sm: new Ext.grid.RowSelectionModel({singleSelect: true}), 
		tbar:[{
			text:'inserisci',
			handler: function(){
// 				var nuovo = new insertUnita({
// 					ragsociale:'',
// 					citta:'',
// 					via:'',
// 					civico:''
// 
// 				});
// 				gridUnita.stopEditing();
// 				dsUnita.insert(0,nuovo);
// 				gridUnita.startEditing(0,0);
			
				var finUnitaLoc = new Attivita.unitaloc.WinEdit({
 					listeners:{unitLocaladded: function(){
						Ext.getCmp('attivitaForm_UnitaLocali').getStore().reload();	//registrazione all'evento 'recordadded' della window che effettua il broadcast dell'omonimo evento sulla form
				}}
				});
				finUnitaLoc.show();
				//console.log('attivitaForm - idattivita:  '+Ext.getCmp('idAttivita').getValue());
				finUnitaLoc.setIdAttivita(Ext.getCmp('idAttivita').getValue());
				
			}
			
		},{
			text:'elimina',
			handler: function(){
				
				var selModel = gridUnita.getSelectionModel();
				var selection = selModel.getSelected();
				
				deletedUlTmp.push(selection.data);
				dsUnita.remove(selection);
				

			}	
		
		}],
		listeners: {
			
			cellclick: function(grid, rowIndex, columnIndex, e){
		
//					console.log(columnIndex)
		
//					Ext.getCmp('btn-seleziona').enable();
					if(columnIndex != 0)
						return;
					Ext.get(document.body).mask('caricamento in corso...');
					
			
					//esegue il blocco di istruzioni
					(function(){
						var ds=grid.getStore();
						var record = ds.getAt(rowIndex);
						var finEditUl = new Attivita.unitaloc.WinEdit();
						finEditUl.addListener('show', function(){Ext.get(document.body).unmask()})
						finEditUl.show();
//						appContext.currentAttRecord = record;
						//console.dir(record)
						finEditUl.setRecord(record);
			
//						finEdit.loadUnitaLocali(record.data.idattivita);
						
					}).defer(100)
			
			}
			
		}
	})

// ------------------------------------------






	var datiGenerali = {
		//labelWidth:170,
		title:'Dati generali',
//		xtype:'form',
		items:[panRagSoc,  panCodfiscPiva, panIndir, panCapCitta, panFormaGiur, panLegRapp, panNRea],
		defaults:{anchor:'99%'}
	}

	var datiSpec = {
		labelWidth:170,
		title:'Altri dati', 
		items:[ panNaddetti,  gridIstatSecond],
		defaults:{anchor:'98%'}
	
	}

	var datiNote = {
		title:'Note',
		items:[cicloProd, note],
		defaults:{anchor:'98%'}
	
	}

	var datiUnitaLocali = {
		title:'Unità Locali',
		id:'attivitaForm-tabUnitaLoc',
		items:[gridUnita],
		defaults:{anchor:'98%'}
	
	
	}


	var tabpanel = new Ext.TabPanel({
		autoHeight:true,
		deferredRender:false,  //IMPORTANTE carica tutti i campi dei vari tab alla prima renderizzazione
		items: [datiGenerali, datiSpec, datiNote, datiUnitaLocali],
		layoutOnTabChange: true,  
		activeTab: 0,
		defaults:{layout: 'form', frame: true, autoHeight:true, border: false}
	})

	// --------------------------------------
	
	var deletedUlTmp = []    //array temporaneo dove archivio i record in attesa di essere cancellati o meno

    var deletedIstatTmp = [];
	

	this.saveFormData = function(){

			if(!_this.getForm().isValid()){ 
				Ext.MessageBox.alert('Inserire i dati mancanti!');
				return;
			}	
		
			
			var recordSaving = _this.getForm().getValues();
	
			var aIstatRecords = [];
		
			Ext.each(dsIstatSecond.getModifiedRecords(), function(record){aIstatRecords.push(record.data)}); //carica l'array 'arecords'
		
		
		//carico tutte le variazioni 
		recordSaving.istatSecondari = aIstatRecords;
		recordSaving.istatEliminati = deletedIstatTmp;
		recordSaving.unitaLocaliEliminate = deletedUlTmp;
		
  		var dataparams = Ext.util.JSON.encode(recordSaving)

//  		console.dir(dataparams)
// 		console.log(dataparams)

		
		//_this.fireEvent('recordadded',_this)
		

//			_this.getForm().submit({	
//				url:'/commongest/CommonServlet/anagditte/salvaAttivita',
//				params:dataparams,
//				success:function(form,action){
//				
//					if(action.result.success){
//						
//						if(appContext.currentAttRecord!=null)
//							_this.updateCurrentRecord();
//						else 
//							_this.fireEvent('recordadded', _this);
//						
//						Ext.MessageBox.alert('Avviso','Salvataggio avvenuto');
//							
//					} else Ext.MessageBox.alert('dati non salvati! :  '+action.result.message);
//					},
//				failure:function(){
//						Ext.MessageBox.show({
//								title:'Avviso',
//								msg: 'dati non salvati!  Controlla campi',
//								minWidth: 200,
//								buttons: Ext.Msg.OK
//		
//						});
//				}
//			});
		
		Ext.Ajax.request({
			
			url:'/commongest/CommonServlet/anagditte/salvaAttivita',
			method:'POST',
			params:{json:dataparams},
			
			success: function(resp,opt){
				var respObj = Ext.decode(resp.responseText)
//				console.log(respObj)
				if(respObj.success){
					//console.log(respObj.success)
					
					
					if(appContext.currentAttRecord!=null){
						_this.updateCurrentRecord();
					}	
					else{ 
						//console.log('il record è nuovo')
//					FIREEVENT CHE NON FUNZIONA - DA CONTROLLARE!!!!						
//						try{
//						_this.fireEvent('recordadded', _this); 
//						} catch(e){console.log('errore del fireEvent'+e)}
					}	
					
				 	updatedata = true;
				 	dsIstatSecond.commitChanges();
				 			
				 	Ext.MessageBox.alert('Salvataggio avvenuto');
				} else Ext.MessageBox.alert('dati non salvati! :  '+respObj.message);
			},
			failure: function(resp, opt){
				Ext.MessageBox.alert('dati non salvati!');
			}
		});

		
  		
  		_this.clearUlTmp();
  		
  		_this.clearIstatTmp();
  		
		
	}

	
	this.deleteGridData = function(){

		var dataparams = {json: Ext.util.JSON.encode(deletedUlTmp)}
		Ext.Ajax.request({
			url:'/commongest/CommonServlet/anagditte/cancelAttivita',
			method:'POST',
			params: dataparams,
			success: function(resp,opt){
				var respObj = Ext.decode(resp.responseText)
				if(respObj.success){

					updatedata = true;
				 	dsUnita.commitChanges();
					Ext.MessageBox.alert('Salvataggio avvenuto');

				} else {

					Ext.MessageBox.alert('dati non salvati!');

				}
			},
			failure: function(resp, opt){
				Ext.MessageBox.alert('dati non salvati!');
			}

		});

	}

	
	
	
	
	this.caricaUnitaLocali = function(idattivita){
		
		Ext.getCmp('attivitaForm_UnitaLocali').getStore().load({params: {attivitalocale: idattivita, id_ente: appContext.currentEnte}});
		
		//console.dir(idattivita)

		
	}
	
	                    
	this.isDirty = function(){
		if(deletedTmp.length>0) return true;
		if(dsUnita.getModifiedRecords().length >0) return true;
		return false;
			
	}


	this.deleting = function(){
		if(deletedUlTmp.length>0) return true;
		else return false;
	}

	this.deletingIstat = function(){
		
		if(deletedIstatTmp.length>0) return true;
		else return false;
	}
	
	
	this.appending = function(){
		if(this.getStore().getModifiedRecords().length >0) return true;
		else	return false;
	}


	this.clearUlTmp = function(){
		deletedUlTmp=[];
	
	}
	
	this.clearIstatTmp = function(){
		deletedIstatTmp = [];
		
	}

	var defaults = {
			
		items:[tabpanel],
		//defaults: formDefaults,
		monitorResize:true,
		autoHeight: true,
		frame:true,
 		updateCurrentRecord: function(){
//			console.log(appContext.currentAttRecord);
 			_this.getForm().updateRecord(appContext.currentAttRecord);
 			appContext.currentAttRecord.commit();
 			
 		},
		setRecord: function(record){
			
//		console.dir(record)
			
			record.data.codfisc = record.data.anagrafica.codfisc;
			record.data.partiva = record.data.anagrafica.partiva;
		
			if(record.data.rappresentante)
					record.data.legrapp = record.data.rappresentante.ragsoc;
		
			_this.getForm().loadRecord(record) //espongo la funzione nativa per caricare il form con il record
			
			
			
			//devo normalizzare il json che leggo perchè ci manca la chiave dei valori
			var normRec = [];
			for(key in record.data.istat_secondari ){
				normRec.push( {codice:key,descrizione:record.data.istat_secondari[key]} );
			}
			dsIstatSecond.loadData(normRec)
//  			console.dir(normRec)
		}

	}
 


	//chiama il costruttore della superclasse (Ext.form.FormPanel) creando un array di parametri che mette insieme config e defaults
	Attivita.form.formTab.superclass.constructor.call(this, Ext.apply({},  config , defaults))
	
}

Ext.extend(Attivita.form.formTab, Ext.form.FormPanel);

//Ext.extend(Attivita.form.formTab, Ext.form.FormPanel, {
//	initComponent:function(){
//		
//		Attivita.form.formTab.superclass.initComponent.call(this);
//		this.addEvents('recordadded');
//	}
//});

//registro l'oggetto EditForm
Ext.reg('attivitaformedit', Attivita.form.formTab)
